﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.Security;

namespace BT_web__nhom06.TienIch
{
    public class MyRoleProvider:RoleProvider
    {
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get;
            set;
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetRolesForUser(string username)
        {
            string sqlSelect = "SELECT * FROM [User] WHERE Username=@TenDangNhap";
            DataTable tbl = Tienichsql.ketnoicsdl.ChayLenhSelectDuLieu(sqlSelect, "@TenDangNhap", username);
            string[] mangQuyen;
            if (tbl.Rows.Count == 0)
                mangQuyen = new string[0];
            else
            {
                mangQuyen = new string[1];
                mangQuyen[0] = (string)tbl.Rows[0]["Quyen"];
            }
            return mangQuyen;
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            string sqlSelect = "SELECT * FROM [User] WHERE Username=@TenDangNhap";
            DataTable tbl = Tienichsql.ketnoicsdl.ChayLenhSelectDuLieu(sqlSelect, "@TenDangNhap", username);
            string quyen;
            if (tbl.Rows.Count == 0)
                return false;
            else
            {
                quyen = (string)tbl.Rows[0]["Quyen"];
                return quyen == roleName;
            }
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}